package com.onlineMIS.ORM.DAO.headQ.finance;

import java.util.Date;
import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.onlineMIS.ORM.DAO.BaseDAO;
import com.onlineMIS.ORM.entity.headQ.finance.FinanceBillItem;
import com.onlineMIS.ORM.entity.headQ.finance.FinanceCategory;
import com.onlineMIS.ORM.entity.headQ.finance.FinanceCategoryFlow;
import com.onlineMIS.ORM.entity.headQ.supplier.purchase.PurchaseOrder;

@Repository
public class FinanceBillItemImpl extends BaseDAO<FinanceBillItem> {
	
	@Autowired
	private FinanceBillImpl financeBillImpl;
	

	public List<FinanceBillItem> getAllByCardId(int cardId, boolean b) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceBillItem.class);
		criteria.add(Restrictions.eq("financeCategory.id", cardId));
		List<FinanceBillItem> fBillItems =  getByCritera(criteria, true);
		return fBillItems;
	}
	
	
	/**
	 * 根据客户财务单据号查询收款详细
	 * @param billId
	 * @return
	 */
	public List<FinanceBillItem> selectItemsByBillId(int billId) {
		DetachedCriteria criteria = DetachedCriteria.forClass(FinanceBillItem.class);
		criteria.add(Restrictions.eq("financeBill.id", billId));
		List<FinanceBillItem> fBillItems =  getByCritera(criteria, true);
		return fBillItems;
	}

	public List<FinanceBillItem> selectItem(Date startDate, Date endDate, int id) {
		// 获取预存金单据
		List<Integer> billIds = financeBillImpl.selectBills(startDate,endDate);
		
		if (billIds.size() !=0) {
			DetachedCriteria criteria = DetachedCriteria.forClass(FinanceBillItem.class);
			criteria.add(Restrictions.in("financeBill.id", billIds));
			criteria.add(Restrictions.eq("financeCategory.id", id));
			
			List<FinanceBillItem> fBillItems =  getByCritera(criteria, true);
			return fBillItems;
		}else {
			return null;
		}

	}




	
	

}
